package thread;

/**
 * @author hubert
 * @date 2018/10/10
 * @description MyThread
 */
public class MyThread extends Thread{
	private String threadName;
	private Integer count;

	public MyThread(String threadName,Integer count){
		this.threadName = threadName;
		this.count = count;
	}

	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName()+","+threadName+ ":正在执行....");
		try {
			while (true) {
				if (Thread.currentThread().interrupted()) {
					System.out.println(threadName+"线程中断");
					break;
				} else {
					if (count%2 == 0) {
						//偶数休眠
						Thread.sleep(2000L);
					} else {
						//奇数退出循环
						break;
					}
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		System.out.println(Thread.currentThread().getName()+","+threadName+ ":执行结束");
	}
}
